fix: add structured exit codes for different failure categories (#11)#14
Open
aidandaly24 wants to merge 8 commits intomainfrom
Open
fix: add structured exit codes for different failure categories (#11)#14aidandaly24 wants to merge 8 commits intomainfrom
aidandaly24 wants to merge 8 commits intomainfrom
Conversation
Create src/cli/exit-codes.ts with ExitCode constants and getExitCode() mapping function that classifies errors into specific exit codes.
Replace hardcoded process.exit(1) calls with process.exit(getExitCode(err)) in all 3 error handlers in src/cli/index.ts.
Cover all exit code mappings including access denied, expired tokens, no credentials, commander errors, deploy failures, agent not found, default general error, and priority ordering.
Coverage Report
|
Use direct property casts instead of Record<string, unknown> index access to avoid noUncheckedIndexedAccess issues with constructor.name.
Cast to a specific interface instead of Record<string, unknown> to ensure type-safe property access for code, exitCode, and constructor.
Use Object.assign instead of type assertion for adding properties to Error objects. Reformat to match prettier output.
…code (#11) - Add ResourceNotFoundException error name check to isAgentNotFoundError() to match the AWS SDK error pattern used throughout the codebase - Add test for ResourceNotFoundException mapping to AGENT_NOT_FOUND (5) - Add test for agent not found in deployed state message pattern
Package Tarballaws-agentcore-0.3.0-preview.6.0.tgz How to installnpm install https://github.com/aidandaly24/agentcore-cli/releases/download/pr-14-tarball/aws-agentcore-0.3.0-preview.6.0.tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds structured exit codes for different failure categories, enabling programmatic distinction between failure types in CI/CD pipelines and wrapper scripts.
Closes #11
Changes
New:
src/cli/exit-codes.tsExitCodeconst object with 7 named exit codes (0-6)ExitCodeValuetype for type-safe usagegetExitCode(err: unknown): numberfunction that maps errors to the correct exit codeSUCCESSGENERAL_ERRORINVALID_ARGSAUTH_EXPIREDACCESS_DENIEDAGENT_NOT_FOUNDDEPLOY_FAILEDThe
getExitCode()function checks errors in priority order:isAccessDeniedError()→ACCESS_DENIED(4)isExpiredTokenError()→AUTH_EXPIRED(3)isNoCredentialsError()→AUTH_EXPIRED(3)INVALID_ARGS(2)isStackInProgressError()/isChangesetInProgressError()→DEPLOY_FAILED(6)AGENT_NOT_FOUND(5)GENERAL_ERROR(1)Modified:
src/cli/index.tsgetExitCodefrom./exit-codes.jsprocess.exit(1)calls withprocess.exit(getExitCode(err))New:
src/cli/__tests__/exit-codes.test.tsAcceptance Criteria
getExitCode()correctly mapsisAccessDeniedError()→EXIT_ACCESS_DENIEDgetExitCode()correctly maps expired token errors →EXIT_AUTH_EXPIREDgetExitCode()instead of hardcoded 1EXIT_GENERAL_ERROR(1)